//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "NelsonSiegelFitting.h"
using namespace Cephei::QL::Termstructures::Yield;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Termstructures::Yield::CNelsonSiegelFitting::CNelsonSiegelFitting () 
{
	_pSpinlock = new boost::detail::spinlock ();
    try
    {
#ifdef HANDLE
        _phNelsonSiegelFitting = NULL;
#endif
        _ppNelsonSiegelFitting = new boost::shared_ptr<QuantLib::NelsonSiegelFitting> (new QuantLib::NelsonSiegelFitting ( ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Termstructures::Yield::CNelsonSiegelFitting::CNelsonSiegelFitting (boost::shared_ptr<QuantLib::NelsonSiegelFitting>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phNelsonSiegelFitting = NULL;
#endif
	_ppNelsonSiegelFitting = &childNative;
    
}
Cephei::QL::Termstructures::Yield::CNelsonSiegelFitting::CNelsonSiegelFitting (QuantLib::NelsonSiegelFitting& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phNelsonSiegelFitting = NULL;
#endif
	_ppNelsonSiegelFitting = new boost::shared_ptr<QuantLib::NelsonSiegelFitting> (&childNative);
    
    _NelsonSiegelFittingOwner = owner;
    
}

Cephei::QL::Termstructures::Yield::CNelsonSiegelFitting::CNelsonSiegelFitting (CNelsonSiegelFitting^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phNelsonSiegelFitting = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppNelsonSiegelFitting = new boost::shared_ptr<QuantLib::NelsonSiegelFitting> (copy->GetShared());
        
    }
}
Cephei::QL::Termstructures::Yield::CNelsonSiegelFitting::CNelsonSiegelFitting (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phNelsonSiegelFitting = NULL;
#endif
	if (!t->IsSubclassOf(CNelsonSiegelFitting::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Termstructures::Yield::CNelsonSiegelFitting::CNelsonSiegelFitting (QuantLib::Handle<QuantLib::NelsonSiegelFitting>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phNelsonSiegelFitting = &childNative;
	_ppNelsonSiegelFitting = &static_cast<boost::shared_ptr<QuantLib::NelsonSiegelFitting>>(childNative.currentLink());
    
    _NelsonSiegelFittingOwner = owner;
}
Cephei::QL::Termstructures::Yield::CNelsonSiegelFitting::CNelsonSiegelFitting (QuantLib::Handle<QuantLib::NelsonSiegelFitting> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phNelsonSiegelFitting = &childNative;
	_ppNelsonSiegelFitting = &static_cast<boost::shared_ptr<QuantLib::NelsonSiegelFitting>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Termstructures::Yield::CNelsonSiegelFitting::CNelsonSiegelFitting (QuantLib::NelsonSiegelFitting childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phNelsonSiegelFitting = NULL;
#endif
	_ppNelsonSiegelFitting = new boost::shared_ptr<QuantLib::NelsonSiegelFitting> (new QuantLib::NelsonSiegelFitting (childNative));
    
}
#endif

Cephei::QL::Termstructures::Yield::CNelsonSiegelFitting::~CNelsonSiegelFitting ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppNelsonSiegelFitting != NULL)
    {
	    delete _ppNelsonSiegelFitting;
        _ppNelsonSiegelFitting = NULL;
    }
}
Cephei::QL::Termstructures::Yield::CNelsonSiegelFitting::!CNelsonSiegelFitting ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppNelsonSiegelFitting != NULL)
    {
	    delete _ppNelsonSiegelFitting;
    }
}
QuantLib::NelsonSiegelFitting& Cephei::QL::Termstructures::Yield::CNelsonSiegelFitting::GetReference ()
{
    if (_ppNelsonSiegelFitting == NULL) throw gcnew NativeNullException ();
	return **_ppNelsonSiegelFitting;
}
boost::shared_ptr<QuantLib::NelsonSiegelFitting>& Cephei::QL::Termstructures::Yield::CNelsonSiegelFitting::GetShared ()
{
    if (_ppNelsonSiegelFitting == NULL) throw gcnew NativeNullException ();
	return *_ppNelsonSiegelFitting;
}
QuantLib::NelsonSiegelFitting* Cephei::QL::Termstructures::Yield::CNelsonSiegelFitting::GetPointer ()
{
    if (_ppNelsonSiegelFitting == NULL) throw gcnew NativeNullException ();
	return &**_ppNelsonSiegelFitting;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::NelsonSiegelFitting>& Cephei::QL::Termstructures::Yield::CNelsonSiegelFitting::GetHandle ()
{
	if (_phNelsonSiegelFitting == NULL)
	{
		_phNelsonSiegelFitting = new Handle<QuantLib::NelsonSiegelFitting> (*_ppNelsonSiegelFitting);
	}
	return *_phNelsonSiegelFitting;
}
#endif
bool Cephei::QL::Termstructures::Yield::CNelsonSiegelFitting::HasNative () 
{
	return (_ppNelsonSiegelFitting != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Termstructures::Yield::INelsonSiegelFitting^ Cephei::QL::Termstructures::Yield::CNelsonSiegelFitting_Factory::Create ()
{
    return gcnew CNelsonSiegelFitting ();
}
